package com.springboot.distributed;

import org.springframework.context.annotation.Configuration;

import lombok.extern.log4j.Log4j2;

/**
 * 分布式事务配置
 *
 * @author supu
 * @date 2019-09-12 15:29
 **/
@Log4j2
@Configuration
public class DistributedTransactionConfig {
    /*@Autowired
    private ConsumerConfig consumerConfig;
    @Autowired
    private DataSource dataSource;

    @Bean
    public ZookeeperHandler zookeeperHandler() {
        return new ZookeeperHandler(consumerConfig.getString(ConsumerConfig.ZOOKEEPER_ADDRESS));
    }

    @Bean
    public DistributedTransactionHandler distributedTransactionHandler() {
        log.info("DistributedTransactionHandler is init");
        return new DistributedTransactionHandler();
    }

    @Bean
    public DistributedTransactionDataSourceAdapter distributedTransactionDataSourceAdapter(DistributedTransactionHandler distributedTransactionHandler,
                                                                                           ZookeeperHandler zookeeperHandler) {
        DistributedTransactionDataSourceAdapter dataSourceAdapter = new DistributedTransactionDataSourceAdapter();
        dataSourceAdapter.setDataSource(dataSource);
        dataSourceAdapter.setDistributedTransactionHandler(distributedTransactionHandler);
        dataSourceAdapter.setTransactionMessageHandler(zookeeperHandler);
        return dataSourceAdapter;
    }

    @Bean
    public DistributedDataSourceTransactionManager distributedDataSourceTransactionManager(DistributedTransactionDataSourceAdapter adapter) {
        DistributedDataSourceTransactionManager dataSourceTransactionManager = new DistributedDataSourceTransactionManager();
        dataSourceTransactionManager.setDistributedTransactionDataSourceAdapter(adapter);
        dataSourceTransactionManager.setDataSource(dataSource);
        return dataSourceTransactionManager;
    }*/
}
